import java.io.*;
import org.kwis.msp.lcdui.*;
import org.kwis.msp.lwc.*;

public class ScrollbarComponentEx1 extends Jlet {

	Display displayLCD;

	ShellComponent shell;

	ScrollbarComponent hScrollbar;

	ImageComponent compImage;
	int widthImage = 0;
	int heightImage = 0;

	public ScrollbarComponentEx1(){  
		displayLCD = Display.getDefaultDisplay();
		shell = new ShellComponent();
	}


	protected void startApp(String[] arg0) {

		ContainerScrollbar container = new ContainerScrollbar();

		Image image = null;
		try {
			image = Image.createImage("/Network cable.gif");
		} catch (IOException e) {}

		compImage = new ImageComponent(image);

		widthImage = image.getWidth();
		heightImage = image.getHeight();

		container.addComponent( compImage );

		hScrollbar = new ScrollbarComponent(ScrollbarComponent.HORIZONTAL,0, displayLCD.getWidth(),  0, widthImage, 3);


		hScrollbar.setEventListener(container, null);
		
		container.addComponent( hScrollbar );

		shell.setTitle("    Scrollbar ");
		shell.setWorkComponent( container );
		shell.show();
	}

	protected void destroyApp(boolean arg0) {
	}



class ContainerScrollbar extends ContainerComponent implements EventListener {

		protected void layout() {

			int h_hScrollbar = hScrollbar.getPreferredHeight();
			int w_hScrollbar = getWidth();
			int x_hScrollbar =0;
			int y_hScrollbar = getHeight()-h_hScrollbar;
			

			hScrollbar.configure(x_hScrollbar,y_hScrollbar,w_hScrollbar,h_hScrollbar,SIZE_MASK | POS_MASK);

			compImage.configure(-hScrollbar.getCurrentValue(),0,widthImage,heightImage,SIZE_MASK | POS_MASK);

			int validMax = hScrollbar.getMaximum() - hScrollbar.getViewAmount();
			if(hScrollbar.getCurrentValue()>validMax) {
				hScrollbar.setCurrentValue( validMax );
			}
		}

		public boolean eventNotify(int arg0, int arg1, int arg2, int arg3, Object arg4) {
			invalidate();
			return false;
		}
	}	

}
